package com.jadesoft.stock.rp;

import java.util.Date;
import java.util.List;

import org.springframework.util.Assert;

import com.jadesoft.common.web.AjaxAction;
import com.jadesoft.stock.FundSubBS;
import com.jadesoft.stock.FundSubBSImpl;
import com.jadesoft.stock.entity.FundSubscript;
import com.jadesoft.stock.util.StockUtil;

public class FundSubAction extends AjaxAction {
	private FundSubBS subBs = new FundSubBSImpl();

	public FundSubscript save(FundSubscript sub){
		sub.setUserId(this.getUser().getId());
		String[] strs = StockUtil.splitStock(sub.getFund());
		sub.setFundName(strs[0]);
		sub.setFundCode(strs[1]);
		sub.setUpdateTime(new Date());
		return subBs.save(sub);
	}
	
	public void remove(FundSubscript sub){
		Assert.notNull(sub.getId(),"ID不能为空!");
		sub.setUserId(getUser().getId());
		subBs.remove(sub);
	}
	
	public List<FundSubscript> list(){
		FundSubscript sub = new FundSubscript();
		sub.setUserId(getUser().getId());
		return subBs.list(sub);
	}

}
